<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商户凭证列表</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="__PUBLIC__/admin/favicon.ico">
    <link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/animate.css" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet">
    <link href="__PUBLIC__/admin/js/plugins/iCheck/custom.css" rel="stylesheet">
    <!--<link href="__PUBLIC__/admin/js/layui/css/layui.css" rel="stylesheet">-->

</head>
<include file="Admin@Index:cache"/>
<body class="gray-bg contacts">
<style>
    .table-hover > tbody > tr > td {
        height: 4rem;
    }
</style>
<div class="wrapper wrapper-content animated fadeInRight" oncopy="copyval()">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-content">
                    <h2>未确认凭证列表</h2>

                    <div class="col-sm-12" style="margin-bottom: 1rem">
                        <form role="form" action="__SELF__" method="get">
                            <div class="form-group">
                                <!--<label>商品code</label>-->
                                <input type="text" id="content" placeholder="" name="content" class="form-control">
                            </div>
                            <div>
                                <input  style="padding-bottom: 2px;width: 15%;height: 2.5rem;" autocomplete="off" class="laydate-icon" placeholder="选择时间" id="time" >

                                <input style="display: none" autocomplete="off" class="laydate-icon" placeholder="起始时间" id="start" name="start" > <input style="display: none;"class="laydate-icon"autocomplete="off"placeholder="截止时间" id="end" name="end">

                                <select id="time_type" name='time_type' class="form-control m-b"
                                        style="margin-bottom: 0;padding-top: 3px;display: inline;width: 10%;">
                                    <option value="should_time">选择时间</option>
                                    <option value="ctime">借款时间</option>
                                    <option value="repayment_time">还款时间</option>
                                </select>
                                <button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit" id="search">
                                    <strong>搜索</strong>
                                </button>

                            </div>
                        </form>
                    </div>
                    <br>
                    <table class="table table-striped table-hover">
                        <tbody>
                        <tr>
                            <!--<th class="">选择</th>-->
                            <th>编号</th>
                            <th>借款人姓名</th>
                            <th>借款人手机号</th>
                            <th>出借人姓名</th>
                            <th>借款金额</th>
                            <th>借款时间</th>
                            <th>应还款时间</th>
                            <th>撕毁时间</th>

                            <th>
                                状态
                            </th>
                            <th>备注</th>
                            <th class="client-status">操作</th>

                        </tr>
                        <foreach name="list" item="list">
                            <tr>
                                <td><{$list.numbering}></td>
                                <td><{$list.borrower}></td>
                                <td>
                                    <{$list.mobile}>
                                </td>
                                <td><{$list.lender}></td>
                                <td><{$list.money}></td>
                                <td><{$list.loan_time}></td>
                                <td><{$list.repayment_time}></td>
                                <td><{$list.tear_time}></td>

                                <!--订单状态1未确认,2已确认,3已逾期,4续期,5已坏账,6已撕毁,7被拒绝9已打款-->
                                <td>待确认
                                </td>
                                <td>
                                    <{$list.note}>
                                </td>
                                <td class="client-status">
                                    <!--<a class="btn btn-info btn-rounded " href="javascript:void(0);"-->
                                       <!--onclick="get_certificate_msg('<{$list.numbering}>','<{$list.status}>')">凭证详情</a>-->

                                    <a class="btn btn-danger btn-rounded" rid="<{$list.id}>" href="javascript:void(0);"
                                       onclick="confirm_certificate('<{$list.numbering}>','<{$list.loan_time}>','<{$list.repayment_time}>','<{$list.money}>','<{$list.interest_rate}>','<{$list.lender_id}>','<{$list.mobile}>','<{$list.borrower}>','<{$list.card_id}>','<{$list.note}>');">确认/拒绝凭证</a>
                                </td>
                            </tr>
                        </foreach>
                        </tbody>
                    </table>
                    <input value="" id='ttt' style="display: none">
                    <ul class="pagination">

                        <{$fpage}>

                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
<script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
<script src="__PUBLIC__/admin/js/layer/layer.js"></script>
<script src="__PUBLIC__/admin/js/laydate/laydate.js"></script>
<!-- 自定义js -->
<script src="__PUBLIC__/admin/js/content.js?v=1.0.0"></script>
<script src="__PUBLIC__/admin/js/plugins/fancybox/jquery.fancybox.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/ajaxfileupload.js"></script>

<script>
    $(document).ready(function () {
        $('.contact-box').each(function () {
            animationHover(this, 'pulse');
        });
    });


    $(document).ready(function () {
        $('.fancybox').fancybox({
            openEffect: 'none',
            closeEffect: 'none'
        });
    });

    laydate.render({
        elem:'#time',
        range:true,
        done: function(value, date, endDate){
            $('#time').val(value);
            var time=value.split(' - ');
            $('#start').val(time[0]);
            $('#end').val(time[1]);
        }
    });

   
    //添加凭证
    function confirm_certificate(numbering,loan_time,repayment_time,money,interest_rate,lender_id,mobile,borrower,card_id,note) {
        get_lender(lender_id);
        var html = '';
        html += '<div class="modal-body" id="lists" style="height:100%">';
        html += '<form class="form-horizontal">';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >借款时间：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="borrow_time" disabled value="'+loan_time+'" placeholder="借款时间" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >还款时间：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="repayment_time" disabled value="'+repayment_time+'" placeholder="还款时间" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >借款金额：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="number" id="borrow_money" disabled value="'+money+'" placeholder="借款金额" class="form-control">';
        html += '</div>';
        html += '</div>';

        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >年化利率：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="borrow_money" disabled value="'+interest_rate+'%" placeholder="借款金额" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >出借人：</label>';
        html += '<div class="col-sm-8">';
        html += '<select class="form-control m-b" name="User" id="lender" style="height:3rem">';

        html += '</select>';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >借款人：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="borrow_mobile" disabled value="'+mobile+'" placeholder="借款人身份证/手机号" onchange="get_msg(this.value)" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >借款人姓名：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="borrow_user_name" value="'+borrower+'"  disabled placeholder="借款人姓名" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >借款人身份证号：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="borrow_user_idcard" value="'+card_id+'" disabled placeholder="出借人" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '<div class="form-group">';
        html += '<label class="col-sm-4 control-label" >备注：</label>';
        html += '<div class="col-sm-8">';
        html += '<input type="text" id="mark" disabled value="'+note+'" placeholder="备注" class="form-control">';
        html += '</div>';
        html += '</div>';
        html += '</form>';
        html += '<div class="modal-footer" style="border:0">';
        html += '<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';
        html += '<a href="javascript:void(0);" onclick="confirm_certificates(\''+numbering+'\');" type="button" class="btn btn-primary" >确认凭证</a>';
        html += '<a href="javascript:void(0);" onclick="refuse_certificate(\''+numbering+'\');" type="button" class="btn btn-danger" >拒绝凭证</a>';
        html += '</div>';
        html += '</div>';

        layer.open({
            type: 1, //Page层类型
            area: ['500px', '680px'],
            title: '确认凭证',
            shade: 0.6, //遮罩透明度
            maxmin: true, //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: html
        });
    }

    //获取出借人
    function get_lender(lender_id) {
        $.post('__MODULE__/Mypublic/get_lender', {post: 'ffsdnfweofhfa'}, function (data) {
            console.log(data);
            if (data.code == '1001') {
                var html = '';
                $(data.result).each(function (k, v) {
                    var s='';
                    if(v.id==lender_id){
                        var s='selected';
                    }
                    html += '<option value="' + v.id + '" '+s+'>' + v.name + '</option>';
                });
                $('#lender').html(html);
            } else {
                if (data.status == '0') {
                    layer.msg(data.info, {time: 2000, icon: 5});
                } else {
                    $('#lender').append(data.result);
                }
            }
        });
    }

    //获取借款人信息
    function get_msg(param) {
        $.post('__MODULE__/Mypublic/get_borrow_user_msg', {param: param}, function (data) {
            if (data.code == '1001') {
                $('#borrow_user_name').val(data.result.username);
                $('#borrow_user_idcard').val(data.result.identity_num);
            } else {
                if (data.status == '0') {
                    layer.msg(data.info, {time: 1000, icon: 5});
                } else {
                    layer.msg(data.result, {time: 1000, icon: 5});
                }
            }
        });
    }
    //确认凭证
    function confirm_certificates(numbering) {
        layer.confirm('是否确认凭证？', function () {
            layer.load(2);
            console.log($('#lender').val());
            $.post('__MODULE__/Voucher/confirm_certificate', {
                numbering:numbering,
                lender: $('#lender').val()
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == '1001') {
                    layer.closeAll();
                    layer.msg(data.result,{icon: 1,time:1000}, function(){
                        window.location.reload();
                    });
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {time: 2000, icon: 5});
                    } else {
                        layer.msg(data.result, {time: 2000, icon: 5});
                    }
                }
            })
        });
    }

    //拒绝凭证
    function refuse_certificate(numbering) {
        layer.confirm('是否确认拒绝凭证？', function () {
            layer.load(2);
            $.post('__MODULE__/Voucher/refuse_certificate', {
                numbering:numbering
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == '1001') {
                    layer.closeAll();
                    layer.msg(data.result,{icon: 1,time:1000}, function(){
                        window.location.reload();
                    });
                } else {
                    if (data.status == '0') {
                        layer.msg(data.info, {time: 2000, icon: 5});
                    } else {
                        layer.msg(data.result, {time: 2000, icon: 5});
                    }
                }
            })
        });
    }


    function timetrans(date) {
        var date = new Date(date);//如果date为10位不需要乘1000
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth()) : date.getMonth()) + '-';
        var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
        return Y + M + D;
    }

    //获取凭证信息
    function get_certificate_msg(orderno, status) {
        $.post('__MODULE__/Mypublic/get_certificate_msg', {orderno: orderno}, function (data) {
            if (data.code == '1001') {
                console.log(data);
                var html = '';
                html += '<div class="modal-body" id="lists" style="height:100%">';
                html += '<form class="form-horizontal">';
                html += '<div class="form-group">';
                html += '<label class="col-sm-3 control-label" >借款时间：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="text" id="borrow_time"  disabled value="' + data.result.loan_time + '" placeholder="借款时间" class="form-control">';
                html += '</div>';
                html += '</div>';
                html += '<div class="form-group">';
                html += '<label class="col-sm-3 control-label" >还款时间：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="text" id="repayment_time" disabled value="' + data.result.repayment_time + '" placeholder="还款时间" class="form-control">';
                html += '</div>';
                html += '</div>';
                html += '<div class="form-group">';
                html += '<label class="col-sm-3 control-label" >借款金额：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="number" id="borrow_money" disabled value="' + data.result.money + '"  placeholder="借款金额" class="form-control">';
                html += '</div>';
                html += '</div>';
                html += '<div class="form-group">';
                html += '<label class="col-sm-3 control-label" >实际到账：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="number" id="borrow_money" disabled value="' + data.result.actual_money + '"  placeholder="实际到账金额" class="form-control">';
                html += '</div>';
                html += '</div>';
                html += '<div class="form-group">';
                html += '<label class="col-sm-3 control-label" >年化利率：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="text" disabled value="' + data.result.interest_rate + '%" placeholder="借款金额" class="form-control">';
                html += '</div>';
                html += '</div>';
                html += '<div class="form-group">';
                html += '<label class="col-sm-3 control-label" >备注：</label>';
                html += '<div class="col-sm-8">';
                html += '<input type="text" disabled value="' + data.result.note + '" placeholder="备注" class="form-control">';
                html += '</div>';
                html += '</div>';
                html += '</form>';
                html += '<div class="modal-footer" style="border:0">';
                html += '<a href="javascript:void(0);" onclick="layer.closeAll()" type="button" class="btn btn-default" >关闭</a>';
                html += '</div>';
                html += '</div>';
                layer.open({
                    type: 1, //Page层类型
                    area: ['500px', '430px'],
                    title: '凭证详情',
                    shade: 0.6, //遮罩透明度
                    maxmin: true, //允许全屏最小化
                    anim: 1, //0-6的动画形式，-1不开启
                    content: html
                });
            } else {
                if (data.status == '0') {
                    layer.msg(data.info, {time: 1000, icon: 5});
                } else {
                    layer.msg(data.result, {time: 1000, icon: 5});
                }
            }
        });
    }






    function copyval() {
//        event.returnValue = false;
        var content = window.getSelection().toString();
        $.post('__MODULE__/Mypublic/copy_all', {content: '【未确认凭证列表】复制：'+content}, function (data) {
            if (data.code == '1001') {
            } else {
                console.log(data);
            }
        });
//        console.log(content)
    }
</script>


</body>

</html>
